package com.start.shop.modules.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.start.shop.modules.repository.dao.GoodsDao;
import com.start.shop.modules.repository.entity.Goods;
import com.start.shop.modules.repository.entity.GoodsType;
import com.start.shop.modules.service.IGoodsService;



 /**
 * 商品类
 *
 */
@Service
public class GoodsServiceImpl implements IGoodsService {

	private Logger logger = LoggerFactory.getLogger(IGoodsService.class);

	@Autowired
	GoodsDao goodsDao;
	
	/*
	 * 查询所有商品类型
	 */
	@Override
	@Cacheable(cacheNames = "Shop::getAllGoodsType",key = "'GoodsType'")
	public List<GoodsType> getAllGoodsType() {
		return goodsDao.selectAllGoodsType();
	}
	

	@Override
	@Cacheable(cacheNames = "Shop::getGoodsTypeByTypeId", key = "'goodsType'-#goodsType")
	public GoodsType getGoodsTypeByTypeId(int goodsType) {
		return goodsDao.selectGoodsTypeByTypeId(goodsType);
	}

	
	
	/*
	 * 查询指定类型所有商类型
	 */
	@Override
	@Cacheable(cacheNames = "Shop::getAllGoods",key = "'Goods'")
	public List<Goods> getAllGoods() {
		return goodsDao.selectAllGoods();
	}

	/*
	 * 查询指定类型所有商品的信息
	 */
	@Override
	@Cacheable(cacheNames = "Shop::getAllGoodsByTypeId", key = "#goodsType")
	public List<Goods> getAllGoodsByTypeId(int goodsType) {
		return goodsDao.selectAllGoodsByTypeId(goodsType);
	}
	
	
	
	/*
	 * 查询指定商品信息
	 */
	@Override
	@Cacheable(cacheNames = "Shop::getGoodsByGoodsId", key = "'goods' + #goodsId")
	public Goods getGoodsByGoodsId(int goodsId) {
		return goodsDao.selectGoodsByGoodsId(goodsId);
	}


}
